<template>
	<view class="brokerage">
		<view class="head-card">
			<image src="@/static/images/jb.png" mode="aspectFit"></image>
			<view class="info-1">
				<text>积分余额</text>
			</view>
			<view class="info-2">
				<text>{{ info.total_jifen || 0 }}</text>
				<text>积分</text>
			</view>
			<u-divider lineColor="#fff" style="margin: 0"></u-divider>
			<view class="info-3">
				<view class="info-1">
					<text>积分总和</text>
					<text>{{ info.total_jifen + info.total_cost }}积分</text>
				</view>
				<view class="divider-y"></view>
				<view class="info-1">
					<text>使用积分</text>
					<text>{{ info.total_cost || 0 }}积分</text>
				</view>
			</view>
		</view>

		<view class="container">
			<view class="u-tabs-box">
				<u-tabs
					:current="current"
					:list="tabList"
					@click="cTab"
					:scrollable="false"
					itemStyle="height: 88rpx;font-weight: bold;"
					inactiveStyle="font-size: 24rpx;"
					lineColor="#E54E4E"
				></u-tabs>
			</view>
			<view class="listbox">
				<j-yongJinList jf :list="list"></j-yongJinList>
				<u-loadmore :status="status" />
			</view>
		</view>
		<footer-btn
			text="前往兑换商品"
			@submit="submit"
			:btnStyle="{
				color: '#53361E',
				background: 'linear-gradient(135deg, #ffe9cc 0%, #f2cea1 100%)'
			}"
		></footer-btn>
	</view>
</template>

<script>
import API from '@/common/api';
export default {
	name: 'brokerage',
	data() {
		return {
			status: '',
			current: 0,
			tabList: [
				{
					name: '全部'
				},
				{
					name: '收入'
				},
				{
					name: '支出'
				}
			],
			info: {},
			list: [],
			paging: {
				page: 1,
				pagenum: 10
			}
		};
	},
	onLoad() {
		this.reset();
		this.get_data();
		this.init();
	},
	onReachBottom() {
		if (this.status === 'nomore') return;
		this.init(this.current);
	},
	methods: {
		submit() {
			this.toNav(`jifenshangcheng/jifenshangcheng`);
		},
		cTab(e) {
			this.reset();
			this.current = e.index;
			this.init();
		},
		get_data() {
			this.$http.getJson('users_jifenInfo', {}).then((res) => {
				const { code, data, message } = res;
				if (code == 1) {
					this.info = res.data;
				}
			});
		},
		reset(){
			this.paging.page = 1;
			this.list = [];
		},
		init() {
			this.status = 'loading';
			API.getJson('users_jifenRecord', { type: this.current, ...this.paging }).then((res) => {
				const { code, data, message } = res;
				if (code === 1) {
					if (data.length !== 0) this.list = this.list.concat(data);
					if (this.paging.pagenum === data.length) {
						this.paging.page += 1;
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
					console.log('users_jifenRecord', data);
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
.brokerage {
	.divider-y {
		width: 1rpx;
		height: 100%;
		margin: 0 24rpx;
		background-color: #f2f2f2;
	}
	.u-tabs-box {
		height: 88rpx;
		background: #ffffff;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
	}
	.container {
		padding: 24rpx 32rpx;
	}
	.listbox {
		padding-top: 24rpx;
	}
	.head-card {
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 750rpx;
		height: 248rpx;
		padding: 26rpx 32rpx;
		background: linear-gradient(135deg, #ffe9cc 0%, #f2cea1 100%);
		image {
			position: absolute;
			top: 0;
			right: 0;
			width: 200.38rpx;
			height: 214.7rpx;
		}
		.info-1 {
			.flex-between();
			font-size: 24rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #53361e;
			text:nth-of-type(1) {
				font-weight: bold;
			}
		}
		.info-2 {
			text:nth-of-type(1) {
				margin-right: 8rpx;
				font-size: 56rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #53361e;
			}
			text:nth-of-type(2) {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #53361e;
			}
		}
		.info-3 {
			display: flex;
			.info-1 {
				flex: 1;
			}
		}
	}
}
</style>
